package doublelist;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;

public class LinkedHashMapDemo {
    //Map,LinkedHashMap,HashMap，TreeMap的区别
    //Map是双列集合的顶层接口，HashMap是Map的实现类，LinkedHashMap是HashMap的子类
    //HashMap是无序的，LinkedHashMap是有序的
    //TreeMap是有序的，默认是自然排序，也可以指定Comparator排序
    public static void main(String[] args) {
        LinkedHashMap<Student,String> lm = new LinkedHashMap<>();
        //添加
        lm.put(new Student("张三",18),"北京");
        lm.put(new Student("李四",19),"上海");
        lm.put(new Student("王五",20),"广州");
        //遍历
        Set<Map.Entry<Student,String>> set = lm.entrySet();
        for (Map.Entry<Student,String> entry : set) {
            System.out.println(entry.getKey() + " " + entry.getValue());
        }
    }

}
